package acp

import (
	"barge/pkg/uix"
	"crypto/tls"
	"github.com/go-resty/resty/v2"
	"os"
	"strings"
)

type Option struct {
	Name    string
	Host    string
	Token   string
	Cluster string
}

type Controller struct {
	*Option
	*resty.Client
}

func NewController(opt *Option) *Controller {
	if !strings.HasPrefix(opt.Host, "https://") {
		opt.Host = `https://` + opt.Host
	}
	opt.Host = strings.TrimSuffix(opt.Host, "/")
	if opt.Token == "" {
		opt.Token = uix.Input("input token:")
	}
	if opt.Token == "" {
		os.Exit(0)
	}
	return &Controller{
		Option: opt,
		Client: resty.New().SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}),
	}
}
